// 引入路由组件，@代表src目录的绝对路径

import Home from '@/views/home'
import Category from '@/views/category'
import Cart from '@/views/cart'
import Mine from '@/views/mine'
import Detail from '@/views/detail'
import NavBar from '@/components/nav-bar'
import TabBar from '@/components/tab-bar'
import SubCategory from '@/views/category/SubCategory'
import Login from '@/views/login'
import Confirm from '@/views/confirm'

// 定义路径数组
const routes = [
  {
    path: '/', // 路由地址
    redirect: 'home',
    components: { // 注册组件
      header: NavBar,
      default: Home,
      footer: TabBar,
    },
  },
  {
    path: '/home', // 路由地址
    components: { // 注册组件
      header: NavBar,
      default: Home,
      footer: TabBar,
    },
    meta: { // meta,路由元信息，是在开发过程中需要使用到的一些额外数据
      inTabBar: true, // 是否显示到 tabbar 上
      title: '首页', // 显示的文本标题
      icon: '&#xe626;', // tabbar 图标 Unicode 编码
    },
  },
  {
    path: '/category',
    components: {
      header: NavBar,
      default: Category,
      footer: TabBar,
    },
    children: [ // 子路由、嵌套路由
      {
        path: 'sub-category/:cid?',
        component: SubCategory,
      },
    ],
    meta: {
      inTabBar: true,
      title: '分类',
      icon: '&#xe605;',
    },
  },
  {
    path: '/cart',
    components: {
      header: NavBar,
      default: Cart,
    },
    meta: {
      inTabBar: true,
      title: '购物车',
      icon: '&#xe60a;',
    },
  },
  {
    path: '/mine',
    components: {
      header: NavBar,
      default: Mine,
      footer: TabBar,
    },
    meta: {
      inTabBar: true,
      title: '我的',
      icon: '&#xe63a;',
      permission: true, // 是否需要验证用户登录
    },
  },
  {
    path: '/detail',
    components: {
      header: NavBar,
      default: Detail,
    },
    meta: {
      title: '商品详情',
    },
  },
  {
    path: '/confirm',
    name: 'confirm',
    components: {
      header: NavBar,
      default: Confirm,
    },
    meta: {
      title: '提交订单页',
      permission: true, // 是否需要验证用户登录
    },
  },
  {
    path: '/login',
    name: 'login',
    components: {
      header: NavBar,
      default: Login,
    },
    meta: {
      title: '登录',
    },
  },

]
export default routes
